#include <stdio.h>
#include <string.h>
#define maxsize 100001
struct friends
{
    char fri[maxsize][4];
}circle[101];

struct QueueData
{
    char name[4];
    int time;
    int pime;
}queue[maxsize];

int s[maxsize];
int len[101];
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    if (m)
    {
        for (int i = 0; i < m; i++)
        {
            int l;
            scanf("%d", &l);
            len[i] = l;
            for (int j = 0; j < l; j++)
            {
                scanf("%s", circle[i].fri[j]);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%s %d %d", queue[i].name, &queue[i].time, &queue[i].pime);
        if (queue[i].pime > 60) queue[i].pime = 60;
    }
    int sum_time = 0;
    int win_time = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 0)
        {
            if (queue[i].time >= win_time)
            {
                win_time += (queue[i].time - win_time) + queue[i].pime;
            }
            else
            {
                sum_time += win_time - queue[i].time;
                win_time += queue[i].pime;
            }

            printf("%s\n", queue[i].name);

            int flag = 0;
            int index = 0;
            for (int j = 0; j < m; j++)
            {
                for (int k = 0; k < len[j]; k++)
                {
                    if (strcmp(queue[i].name, circle[j].fri[k]) == 0)
                    {
                        flag = 1;
                        index = j;
                        break;
                    }
                }
            }
            if (flag)
            {
                for (int j = i + 1; j < n; j++)
                {
                    for (int k = 0; k < len[index]; k++)
                    {
                        if (strcmp(queue[j].name, circle[index].fri[k]) == 0 && s[j] == 0)
                        {
                            if (queue[j].time > win_time) break;
                            sum_time += win_time - queue[j].time;
                            win_time += queue[j].pime;

                            s[j] = 1;
                            printf("%s\n", queue[j].name);
                        }
                    }
                }
            }
        }
        s[i] = 1;
    }
    printf("%.1f", 1.0 * sum_time / n);
    return 0;
}
